﻿<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" autoFlush="true"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<a href="/shoparticle.mrqa?action=admin">返回</a>
<br>
<span class="title1">添加礼品</span>
<table class="qlist" width="100%" align="center" cellpadding="0" cellspacing="0" style="background-color:#FAFCFC;border:1px solid #ccc;">
    <html:form action="/shoparticle" method="post" onsubmit="return validate(this);" enctype="multipart/form-data">
    <html:hidden property="action" value="add"/>
    <tr>
        <td align="right">名称</td>
        <td>
            <html:text property="name" size="18" />
        </td>
    </tr>
    <tr>
        <td align="right">所属分类</td>
        <td>
        	<html:select property="categoryId">
        		<c:forEach var="category" items="${categoryList}">
        			<html:option value="${category.id}">
        				<c:out value="${category.name}"/>
        			</html:option>
        		</c:forEach>
        	</html:select>
        </td>
    </tr>
    <tr>
    	<td align="right">图片</td>
    	<td><html:file property="picture" size="30"/>(格式:JPG,GIF,PNG)</td>
  	</tr>
  	<tr>
    	<td align="right">积分</td>
    	<td><html:text property="money" size="4" /></td>
  	</tr>
  	<tr>
    	<td align="right">数量</td>
    	<td><html:text property="quantity" size="4" /></td>
  	</tr>
  	<tr>
    	<td align="right">说明</td>
    	<td><html:textarea property="description" cols="70" rows="10"/></td>
  	</tr>
  	<tr>
    	<td align="right">奖励用户</td>
    	<td><html:text property="awardUserName" size="12"/></td>
  	</tr>
  	<tr>
    	<td align="right">奖励积分</td>
    	<td><html:text property="awardMoney" size="4" /></td>
  	</tr>
    <tr>
        <td align="right"></td>
        <td>
            <input type="submit" value="添加"/>
        </td>
    </tr>
    </html:form>
</table>
<script type="text/javascript">
    function validate(pForm)
    {
        var name = pForm.name.value;
        if(name == "")
        {
            alert("[名称]必须");
            pForm.name.focus();
            return false;        
        }
        var picture = pForm.picture.value;
        if(picture == "")
        {
            alert("[图片]必须");
            pForm.picture.focus();
            return false;        
        }
        var money = pForm.money.value;
        if(money == "")
        {
            alert("[积分]必须");
            pForm.money.focus();
            return false;        
        }
        var quantity = pForm.quantity.value;
        if(quantity == "")
        {
            alert("[数量]必须");
            pForm.quantity.focus();
            return false;        
        }
        var description = pForm.description.value;
        if(description == "")
        {
            alert("[说明]必须");
            pForm.description.focus();
            return false;
        }
        var awardUserName = pForm.awardUserName.value;
        var awardMoney = pForm.awardMoney.value;
        if(awardUserName != "" && awardMoney == ""){
        		alert("请填写[奖励积分]");
            pForm.awardMoney.focus();
            return false;
        }
        if(awardUserName == "" && awardMoney != ""){
        		alert("请填写[奖励用户]");
            pForm.awardUserName.focus();
            return false;
        }
        return true;
    }
</script>